<template>
  <div>
    <f-table ref='table' rowKey='paymentId' size='small' :showSetting='true' setting-key='sb1' :tableColumns='columns' :multiple='false' :operator='operator' :scroll='scroll' :params='queryParam' :api='api.payment' handler='customBondPageListHandler'>
     <span slot='paymentState' slot-scope='text, record, index'>
            <a-tag color='#87d068' v-if='text==0'>未提交</a-tag>
             <a-tag color='#108ee9' v-if='text==1' @click='processImg(record)'>{{ record.taskName }}</a-tag>
            <a-tag color='#f50' v-if='text==2' @click='processImg(record)'>已审批</a-tag>
        </span>
      <span slot='returnState' slot-scope='text, record, index'>
            <a-tag color='#87d068' v-if='text==0'>未退款</a-tag>
            <a-tag color='#f50' v-if='text==1' >已退款</a-tag>
        </span>
      <span slot='action' slot-scope='text, record'>
          <template>
            <a @click='$refs.drawer.showDrawer(record,"form2")'>查看</a>
            <a-divider type='vertical' />
            <a @click='startProcess(record)' v-if='record.paymentState==0'>提交</a>
             <a-divider type='vertical' v-if='record.paymentState==0'/>
          </template>
            <a-dropdown>
            <a class='ant-dropdown-link'>更多 <a-icon type='down' /></a>
            <a-menu slot='overlay'>
              <a-menu-item v-if='record.paymentState!=0'>
                <a href='javascript:;' @click='processImg(record)'>审批进度</a>
              </a-menu-item>
              <a-menu-item v-if="record.paymentState==0||(record.taskDefinitionKey&&record.taskDefinitionKey=='__initiator__')">
                <a href='javascript:;' @click="$refs.table.del(record,{handlerName:'customBondPaymentDeleteHandler'})">删除</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
    </f-table>
    <custom-bond-drawer ref='drawer' @success='onLoad'></custom-bond-drawer>
    <order-info-drawer ref='orderInfoDrawer'></order-info-drawer>
    <process-image ref='processImg' v-if='processImageVisible' :visible.sync='processImageVisible' :processInstanceId='processInstanceId'></process-image>
  </div>
</template>
<script>
import api from "./../js/api"
import CustomBondDrawer from "./custombond_drawer"
import ProcessImage from "../../../flowable/process/process_image"
import OrderInfoDrawer from "../../../business/order/order_info_drawer"

export default {
  name: "CustomBondNo",
  components: {
    OrderInfoDrawer,
    ProcessImage,
    CustomBondDrawer
  },
  data() {
    let me = this
    //操作按钮
    let operator = []
    operator.push({
      name: "添加",
      icon: "plus",
      that: this,
      handler: function(table, that) {
        that.$refs.drawer.showDrawer(null, "form1")
      }
    })
    return {
      api: Object.assign(api, this.api),
      //列表初始化查询参数
      queryParam: {},
      processImageVisible: false,
      scroll: { x: true },
      // 表头
      columns: [
        {
          title: "序号",
          width: "50px",
          align: "left",
          customRender: (text, record, index) => index + 1
        },
        {
          title: "操作",
          align: "center",
          dataIndex: "action",
          width: "150px",
          scopedSlots: { customRender: "action" }
        },
        {
          title: "单号",
          align: "left",
          width: "125px",
          dataIndex: "paymentNo"
        },
        {
          title: "部门",
          align: "left",
          width: "80px",
          dataIndex: "deptName"
        },
        {
          title: "业务员",
          align: "left",
          width: "100px",
          dataIndex: "saleManName"
        },
        {
          title: "收款金额",
          align: "left",
          width: "100px",
          dataIndex: "amount"
        },
        {
          title: "收款日期",
          align: "left",
          width: "100px",
          dataIndex: "amountDate"
        },
        {
          title: "已退金额",
          align: "left",
          width: "100px",
          dataIndex: "returnAmount"
        },
        {
          title: "制单人",
          align: "left",
          width: "100px",
          dataIndex: "nickName"
        },
        {
          title: '退款状态',
          align: 'left',
          needTotal: true,
          width: '80px',
          dataIndex: 'returnState',
          scopedSlots: { customRender: "returnState" }
        },
        {
          title: "审批状态",
          align: "left",
          width: "130px",
          dataIndex: "paymentState",
          scopedSlots: { customRender: "paymentState" }
        }, {
          title: "创建日期",
          align: "left",
          width: "100px",
          dataIndex: "createTime"
        }
      ],
      operator: operator
    }
  },
  created() {
  },
  methods: {
    onLoad() {
      this.$refs.table.refresh()
      this.$emit("changeTab")
    },
    //流程图
    processImg(order) {
      this.processInstanceId = order.processInstanceId
      this.processImageVisible = true
    },
    startProcess(payment) {
      this.http.confirm(this, {
        content: "确认提交审批吗?",
        url: api.processInstance.start,
        requestBody: true,
        data: {
          handlerName: "customBondStartProcessHandler",
          businessKey: payment.paymentId
        },
        success: function(me, data) {
          me.$refs.table.refresh()
        }
      })
    }
  }
}
</script>
